package main

import (
	"fmt"
	"strconv"
)

type Good interface {
	settleAccount() int
	orderInfo() string
}

type Phone struct {
	name     string
	quantity int
	price    int
}

func (phone Phone) settleAccount() int {
	return phone.quantity * phone.price
}

func (phone Phone) orderInfo() string {
	return "您要购买" + strconv.Itoa(phone.quantity) + "个" + phone.name + "计:" + strconv.Itoa(phone.settleAccount()) + "元"
}

type FreeGift struct {
	name     string
	quantity int
	price    int
}

func (gift FreeGift) settleAccount() int {
	return 0
}

func (gift FreeGift) orderInfo() string {
	return "您要购买" + strconv.Itoa(gift.quantity) + "个" + gift.name + "计:" + strconv.Itoa(gift.settleAccount()) + "元"
}
func calculateAllPrice(goods []Good) int {
	var allPrice int
	for _, good := range goods {
		fmt.Println(good.orderInfo())
		allPrice += good.settleAccount()
	}
	return allPrice
}
func mainqwer() {
	test := new(Phone)
	test2 := new(Good)
	fmt.Println(*test)
	fmt.Println(*test2)
	iPhone := Phone{
		name:     "iphone",
		quantity: 1,
		price:    800,
	}

	earPhones := FreeGift{
		name:     "耳机",
		quantity: 1,
		price:    200,
	}

	goods := []Good{iPhone, earPhones}
	allPrice := calculateAllPrice(goods)
	fmt.Println("该订单总共要支付%d元", allPrice)

}
